<?php

namespace App\Admin\Grid\Tools;

use App\Models\MaterialUnit;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Illuminate\Http\Request;

class AddUnit extends AbstractTool
{

    protected $style = 'btn btn-primary btn-outline';

    /**
     * 标题
     *
     * @return string
     */
    public function title()
    {
        return '新增';
    }


    /**
     * 处理请求
     *
     * @param Request $request
     *
     * @return \Dcat\Admin\Actions\Response
     */
    public function handle(Request $request)
    {
        $bookId = $this->getKey();
        MaterialUnit::factory()->create([
            'book_id' => $bookId,
            'mechanism_id' => Admin::user()->id
        ]);
        return $this->response()->success('新增成功')->refresh();
    }
}
